package com.arrcen.medicen.core.match.ctrl;


import com.arrcen.medicen.core.match.model.dto.DtoPage;
import com.arrcen.medicen.core.match.model.dto.DtoPageKey;
import com.arrcen.medicen.core.match.model.dto.ResultObj;
import com.arrcen.medicen.core.match.model.entity.ScheduleTaskEntity;
import com.arrcen.medicen.core.match.model.entity.ScheduleTaskTableEntity;
import com.arrcen.medicen.core.match.service.ScheduleTask;
import com.arrcen.medicen.core.match.utlity.LogHelper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping("Schedule")
public class ScheduleController {

    @Autowired
    ScheduleTask scheduleTask;

    @Resource
    LogHelper logHelper;

    @RequestMapping(value = "xxlJobRun", method = RequestMethod.GET)
    @ApiOperation(value = "启动运行，开始同步数据")
    @XxlJob("syncData")
    public void xxlJobRun() {
        logHelper.resetTime();
        logHelper.info(ScheduleController.class,"开始执行xxlJobRun");
        scheduleTask.xxlJobRun();
        logHelper.info(ScheduleController.class,"结束执行xxlJobRun");

    }


    @RequestMapping(value = "getTaskList", method = RequestMethod.POST)
    @ApiOperation(value = "获取调度日志列表")
    public ResultObj<IPage<ScheduleTaskEntity>> getTaskList(@RequestBody DtoPage dtoPage) {
        ResultObj<IPage<ScheduleTaskEntity>> listResultObj = new ResultObj<>();
        listResultObj.setData(scheduleTask.getTaskList(dtoPage));
        listResultObj.setStatus(1);
        return listResultObj;
    }


    @RequestMapping(value = "getTaskTableList", method = RequestMethod.POST)
    @ApiOperation(value = "获取调度日志列表")
    public ResultObj<IPage<ScheduleTaskTableEntity>> getTaskTableList(@RequestBody DtoPageKey dtoPage) {
        ResultObj<IPage<ScheduleTaskTableEntity>> listResultObj = new ResultObj<>();
        listResultObj.setData(scheduleTask.getTaskTableList(dtoPage));
        listResultObj.setStatus(1);
        return listResultObj;
    }

}
